home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Freeware / First Page 2006 3.00 / fp2006-final-3.00-setup.exe / {app} / Iscripts / DHTML - Window and Frames / open-select-links-in-new-window.izs < prev    next >
Text File  |  2005-09-02  |  5KB  |  133 lines

  1. <!NOWIZARD>
  2.  
  3. <!TITLE>Open select links in new window
  4. <!/TITLE>
  5.  
  6. <!BROWSER>FF1+ IE5+ Opr7+<!/BROWSER>
  7.  
  8. <!DESCRIPTION>This one of a kind script makes it easy to specify certain links on your page open in a new window, and with greater control than HTML's "target" attribute. You can designate arbitrary links- or even entire groups of links- open in a new window by doing one of the following:
  9.  
  10. 1) Give the link a class="nwindow" attribute.
  11. 2) Or, to get an entire group of links to open in a new window, wrap them all inside a container with class="nwindowcontainer", such as <div class="nwindowcontainer">links here</div>.
  12.  
  13.  
  14. <!/DESCRIPTION> 
  15.  
  16. <!CATEGORY>window and frames<!/CATEGORY>
  17.  
  18. <!SCRIPT>
  19. <!-- START OF SCRIPT -->
  20. <script type="text/javascript">
  21.  
  22. /***********************************************
  23. * Open select links in new window script- ⌐ Dynamic Drive DHTML code library (www.dynamicdrive.com)
  24. * This notice MUST stay intact for legal use
  25. * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
  26. ***********************************************/
  27.  
  28. /*****************USAGE NOTES:*****************
  29. Add: <form name="targetmain"><input type="checkbox" name="targetnew" checked onClick="applywindow(targetlinks)">Open designated links in new window</form>
  30.  
  31. anywhere on your page to automatically switch the script to manual mode, whereby only checking a checkbox will cause designated links to open in a new window. Customize the form as desired, but preserve key information such as the name attributes and onClick command. Remove form to switch back to auto mode.
  32. ***********************************************/
  33.  
  34. var linktarget="_blank" //Specify link target added to links when set to open in new window
  35.  
  36. var formcache=document.targetmain
  37.  
  38. function applywindow(){
  39. if (typeof targetlinks=="undefined") return
  40. if (!formcache || (formcache && formcache.targetnew.checked)){
  41. for (i=0; i<=(targetlinks.length-1); i++)
  42. targetlinks[i].target=linktarget
  43. }
  44. else
  45. for (i=0; i<=(targetlinks.length-1); i++)
  46. targetlinks[i].target=""
  47. }
  48.  
  49.  
  50. function collectElementbyClass(){
  51. if (!document.all && !document.getElementById) return
  52. var linksarray=new Array()
  53. var inc=0
  54. var alltags=document.all? document.all : document.getElementsByTagName("*")
  55. for (i=0; i<alltags.length; i++){
  56. if (alltags[i].className=="nwindow")
  57. linksarray[inc++]=alltags[i]
  58. if (alltags[i].className=="nwindowcontainer"){
  59. var alldivlinks=document.all? alltags[i].all.tags("A") : alltags[i].getElementsByTagName("A")
  60. for (t=0; t<alldivlinks.length; t++)
  61. linksarray[inc++]=alldivlinks[t]
  62. }
  63. }
  64. return linksarray
  65. }
  66. if (formcache && formcache.targetnew.checked) //overcome IE bug, manually check checkbox that has "checked" attribute
  67. setTimeout("document.targetmain.targetnew.checked=true",100)
  68. var targetlinks=collectElementbyClass()
  69. applywindow()
  70.  
  71. </script>
  72. <!-- END OF SCRIPT -->
  73. <!/SCRIPT>
  74.  
  75. <!PREVIEW>
  76. <!-- START OF SCRIPT -->
  77. <script type="text/javascript">
  78.  
  79. /***********************************************
  80. * Open select links in new window script- ⌐ Dynamic Drive DHTML code library (www.dynamicdrive.com)
  81. * This notice MUST stay intact for legal use
  82. * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
  83. ***********************************************/
  84.  
  85. /*****************USAGE NOTES:*****************
  86. Add: <form name="targetmain"><input type="checkbox" name="targetnew" checked onClick="applywindow(targetlinks)">Open designated links in new window</form>
  87.  
  88. anywhere on your page to automatically switch the script to manual mode, whereby only checking a checkbox will cause designated links to open in a new window. Customize the form as desired, but preserve key information such as the name attributes and onClick command. Remove form to switch back to auto mode.
  89. ***********************************************/
  90.  
  91. var linktarget="_blank" //Specify link target added to links when set to open in new window
  92.  
  93. var formcache=document.targetmain
  94.  
  95. function applywindow(){
  96. if (typeof targetlinks=="undefined") return
  97. if (!formcache || (formcache && formcache.targetnew.checked)){
  98. for (i=0; i<=(targetlinks.length-1); i++)
  99. targetlinks[i].target=linktarget
  100. }
  101. else
  102. for (i=0; i<=(targetlinks.length-1); i++)
  103. targetlinks[i].target=""
  104. }
  105.  
  106.  
  107. function collectElementbyClass(){
  108. if (!document.all && !document.getElementById) return
  109. var linksarray=new Array()
  110. var inc=0
  111. var alltags=document.all? document.all : document.getElementsByTagName("*")
  112. for (i=0; i<alltags.length; i++){
  113. if (alltags[i].className=="nwindow")
  114. linksarray[inc++]=alltags[i]
  115. if (alltags[i].className=="nwindowcontainer"){
  116. var alldivlinks=document.all? alltags[i].all.tags("A") : alltags[i].getElementsByTagName("A")
  117. for (t=0; t<alldivlinks.length; t++)
  118. linksarray[inc++]=alldivlinks[t]
  119. }
  120. }
  121. return linksarray
  122. }
  123. if (formcache && formcache.targetnew.checked) //overcome IE bug, manually check checkbox that has "checked" attribute
  124. setTimeout("document.targetmain.targetnew.checked=true",100)
  125. var targetlinks=collectElementbyClass()
  126. applywindow()
  127.  
  128. </script>
  129.  
  130. <!-- END OF SCRIPT -->
  131. <!/PREVIEW>
  132.  
  133. <!RELATED>NONE<!/RELATED>